package com.example.smartcity_poverty.ui.AllService.Attorneys.fragment

import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.LinearLayoutManager
import com.example.smartcity_poverty.App.Companion.getToken
import com.example.smartcity_poverty.R
import com.example.smartcity_poverty.logic.Repository.api
import com.example.smartcity_poverty.logic.Repository.coroutine
import com.example.smartcity_poverty.logic.model.Attreneys.AttUserListAllModel
import com.example.smartcity_poverty.logic.util.Util.show
import com.example.smartcity_poverty.ui.AllService.Attorneys.adapter.AttUserListAdapter
import com.example.smartcity_poverty.ui.AllService.Attorneys.fragment.AttorneysHomeFragment.Companion.AttId
import kotlinx.android.synthetic.main.fragment_attorneys_me.*
import kotlinx.coroutines.Dispatchers

/**
 * 律师咨询功能模块描述
 */
class AttorneysMeFragment : Fragment() {
    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_attorneys_me, container, false)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        coroutine(Dispatchers.IO){
            api.getAttUserListAll(getToken(), MeId).apply {
                if (this.code == 200){
                    activity?.runOnUiThread {
                        this.rows?.let { it ->
                            attUserListAllRv.apply {
                                this.layoutManager = LinearLayoutManager(context)
                                this.adapter = AttUserListAdapter(ArrayList<AttUserListAllModel.RowsBean>().apply {
                                    this.addAll(it)
                                }, R.layout.re_att_show_list_comment)
                            }
                        }
                    }
                }else activity?.runOnUiThread { this.msg?.show() }
            }
        }
    }

    companion object{
        var MeId = 0
    }

}